<?php

namespace app\api\model;

use app\common\model\OrderGoods as OrderGoodsModel;

/**
 * 订单商品模型
 * Class OrderGoods
 * @package app\api\model
 */
class OrderGoods extends OrderGoodsModel
{
    /**
     * 隐藏字段
     * @var array
     */
    protected $hidden = [
        'content',
        'wxapp_id',
        'create_time',
    ];

    /**
     * 获取未评价的商品
     * @param $order_id
     * @return OrderGoods[]|false
     * @throws \think\exception\DbException
     */
    public static function getNotCommentGoodsList($order_id)
    {
        return self::all(['order_id' => $order_id, 'is_comment' => 0], ['orderM', 'image']);
    }

    /**
     * 创建抽奖订单商品
     */
    public static function createLotteryOrderGoods($order_id, $user_id, $goods)
    {
        return self::create([
            'goods_id' => $goods->goods_id,
            'goods_name' => $goods->goods_name,
            'image_id' => $goods->image ? $goods->image[0]->id : 0,
            'deduct_stock_type' => $goods->deduct_stock_type,
            'content' => $goods->content,
            'total_num' => 1,
            'order_id' => $order_id,
            'user_id' => $user_id,
            'wxapp_id' => static::$wxapp_id,
            'create_time' => time()
        ]);
    }

}
